function [y1,y2,y3,y4]=cvplot(ann,plt)

% function [train,test]=cvplot(ann,{plt})
% Plots ann strutured variable
% the type of plot is controled by plt:
% plt=1 -> time series scaled predicted vs scaled observed <default>
% plt=2 -> same as before but with a y log scale
% plt=3 -> predicted vs observed all
% plt=4 -> predicted vs observed test and train discriminated, unscaled
% plt=5 -> like plt=4, but one window for each
% plt=6 -> data vs pred, x axis is the first (and maybe only) input
% plt=7 -> sensitivity analysis
% plt=8 -> error analyzis
% plt=9 -> same as plt=3 but using loglog plot

y1=[];
y2=[];
y3=[];
y4=[];

if nargin<2;plt=1;end

if plt==1
   plot(ann.p.train,ann.y.train,'+')
   hold on
   plot(ann.p.test,ann.y.test,'*')
   plot(ann.p.train,ann.y.ptrain,'o')
   plot(ann.p.test,ann.y.ptest,'o')
   title('legend: train +, test *, ann o')
   xlabel('data series')
   ylabel('scaled ann outputs')
   hold off
elseif plt==2
   my=length(ann.y.y(1,:));
   semilogy(ann.p.train,ann.y.train,'+')
   hold on
   semilogy(ann.p.test,ann.y.test,'*')
   semilogy(ann.p.train,ann.y.ptrain,'o')
   semilogy(ann.p.test,ann.y.ptest,'o')
   title('legend: train +, test *, ann o')
   xlabel('data series')
   ylabel('scaled outputs')
   hold off 
elseif plt==3
   x=ann.y.y;
   y=cvpreve(ann,ann.x.x);
   my=length(x(1,:));
   for i=1:my
      %figure
      plot(x(:,i),y(:,i),'o')
   	xlabel('observed')
   	ylabel('predicted')
   	r=corrcoef(x(:,i),y(:,i));
      title((r(2,1))^2);
      linha=cvlinha(x(:,i),y(:,i));
      hold on
      plot([min(x(:,i));max(x(:,i))],[min(linha.y);max(linha.y)]);
      plot([min(linha.y);max(linha.y)],[min(linha.y);max(linha.y)],':');
         % Distingwish test points with an '*'
         ntest=length(ann.y.test(:,1));	%  # points
         for j=1:ntest
            plot(x(ann.p.test(j),i),y(ann.p.test(j),i),'*')
         end
      hold off
   end
   % outputs
   y1=x;	% obtained
   y2=y; % predicted
elseif plt==4
   ann=cvcompoe(ann);
   plot(ann.p.train,ann.compoe.ytrain,'+')
   hold on
   plot(ann.p.test,ann.compoe.ytest,'*')
   plot(ann.p.train,ann.compoe.yptrain,'o')
   plot(ann.p.test,ann.compoe.yptest,'o')
   title('legend: train +, test *, ann o')
   xlabel('data series')
   ylabel('unscaled outputs')
   hold off
   y1=[ann.compoe.ytrain,ann.compoe.yptrain];
   y2=[ann.compoe.ytest,ann.compoe.yptest];
elseif plt==5
   ann=cvcompoe(ann);
   for i=1:length(ann.y.y(1,:))
      figure
      plot(ann.p.train,ann.compoe.ytrain(:,i),'+')
   	hold on
   	plot(ann.p.test,ann.compoe.ytest(:,i),'*')
   	plot(ann.p.train,ann.compoe.yptrain(:,i),'o')
   	plot(ann.p.test,ann.compoe.yptest(:,i),'o')
   	title('legend: train +, test *, ann o')
   	xlabel('data series')
   	ylabel('unscaled outputs')
      hold off
   end
elseif plt==6
   ann=cvcompoe(ann);
   plot(ann.x.x(:,1),ann.y.y,'o')
   hold on
   plot(ann.x.x(:,1),cvpreve(ann,ann.x.x),'*')
   title('legend: experimental data o, ann predictions -')
   xlabel('time')
   ylabel('unscaled outputs')
   hold off
elseif plt==7
   for i=1:length(ann.y.y(1,:))	% for each output
      figure
      hold on
      plot(ann.ss(:,:,i),'b+')
      axis([0 (length(ann.x.x(i,:))+1) 0 1])
      plot(ann.s(:,i),'ko')
      plot(ann.s(:,i),'k*')
      hold off
      xlabel('variable')
      ylabel('relative sensitivity')
      title(' o = median ann, + = individual ann')
   end
   y1=ann.s;
   y2=ann.ss;
elseif plt==8
   es=[];
   for i=1:length(ann.anns)	% for each ann
      es=[es;ann.anns(i).ann.erro.test];
   end
   plot(0,es,'b+');
   hold on
   xlabel('individual anns (optimized topology)')
   ylabel('test error')
   plot(0,ann.erro.test,'ko')
   plot(0,ann.erro.test,'k*')
   hold off
   y1=es;
elseif plt==9
   x=ann.y.y;
   y=cvpreve(ann,ann.x.x);
   my=length(x(1,:));
   for i=1:my
      figure
      loglog(x(:,i),y(:,i),'o')
   	xlabel('observed')
   	ylabel('predicted')
   	r=corrcoef(x(:,i),y(:,i));
      title((r(2,1))^2);
      linha=cvlinha(x(:,i),y(:,i))
      hold on
      loglog(sort(x(:,i)),sort(linha.y))
      loglog(sort(linha.y),sort(linha.y),':')
      %loglog([min(x(:,i));max(x(:,i))],[min(linha.y);max(linha.y)],':');
      %loglog([min(linha.y);max(linha.y)],[min(linha.y);max(linha.y)]);
         % Distingwish test points with an '*'
         ntest=length(ann.y.test(:,1));	%  # points
         for j=1:ntest
            loglog(x(ann.p.test(j),i),y(ann.p.test(j),i),'*')
         end
      hold off
   end
end

